package cn.wokoba.trigger.job;


import cn.wokoba.service.activity.model.ActivitySkuStockKeyVO;
import cn.wokoba.service.activity.repository.ActivityRepository;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


// 更新活动sku库存任务


@Slf4j
@Component()
public class UpdateActivitySkuStockJob {


    @Autowired
    ActivityRepository activityRepository;

    //    @Scheduled(cron = "0/15 * * * * ?")
    @XxlJob("UpdateActivitySkuStockJob")
    public void exec() {
        try {
            ActivitySkuStockKeyVO activitySkuStockKeyVO = activityRepository.takeQueueValue();
            if (null == activitySkuStockKeyVO) return;
            log.info("定时任务，更新活动sku库存 sku:{} activityId:{}", activitySkuStockKeyVO.getSku(), activitySkuStockKeyVO.getActivityId());
            activityRepository.updateActivitySkuStock(activitySkuStockKeyVO.getSku());

        } catch (Exception e) {
            log.error("定时任务，更新活动sku库存失败", e);
        }
    }

}
